// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html

cc.Class({
    extends: cc.Component,

    properties: {
        numbers: {
            default: [],
            type: cc.Label
        },
        numArr: [],
    },

    refreshNumber: function () {
        var i = 0;
        for (var i = 0; i < this.numArr.length && i < this.numbers.length; i++) {
            this.numbers[i].string = this.numArr[i];
        }
        for (; i < this.numbers.length; i++) {
            this.numbers[i].string = "";
        }
    },
    onNumber: function (target, customData) {
        if (this.numArr.length < 6) {
            this.numArr.push(customData);
        }
        this.refreshNumber();
        if (this.numArr.length === 6) {
            network.send("joinRoom", { roomId: this.numArr.join("") });
        }
    },
    onBack: function () {
        this.numArr.pop();
        this.refreshNumber();
    },
    onClear: function () {
        this.numArr = [];
        this.refreshNumber();
    },
    onClose: function () {
        this.node.destroy();
    },
    onLoad: function () {
        this.numArr = [];
        this.refreshNumber();
    }
});
